import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete
} from '@nestjs/common';
import { ApiOperation, ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { DepartmentService } from './department.service';
import { CreateDepartmentDto, UpdateDepartmentDto } from '@schemas';
import { QueryDepartmentDto } from './dto/queryDepartmentDto';
import { departmentNormalize as norm } from '../../normalize';

@Controller(norm.path)
@ApiTags(norm.tag)
@ApiBearerAuth()
export class DepartmentController {
  constructor(private readonly departmentService: DepartmentService) {}

  @Post(norm.create.path)
  @ApiOperation({ summary: norm.create.tag })
  create(@Body() createRoleDto: CreateDepartmentDto) {
    return this.departmentService.create(createRoleDto);
  }

  @Post(norm.page.path)
  @ApiOperation({ summary: norm.page.tag })
  pageQuery(@Body() dto: QueryDepartmentDto) {
    return this.departmentService.pageQuery(dto);
  }

  @Get(norm.list.path)
  @ApiOperation({ summary: norm.list.tag })
  findAll() {
    return this.departmentService.findAll();
  }

  @Get(norm.recode.path)
  @ApiOperation({ summary: norm.recode.tag })
  findRecode() {
    return this.departmentService.findRecode();
  }

  @Get(norm.detail.path)
  @ApiOperation({ summary: norm.detail.tag })
  findOne(@Param(norm.detail.arg) id: string) {
    return this.departmentService.findOne(id);
  }

  @Patch(norm.update.path)
  @ApiOperation({ summary: norm.update.tag })
  update(
    @Param(norm.update.arg) id: string,
    @Body() updateRoleDto: UpdateDepartmentDto
  ) {
    return this.departmentService.update(id, updateRoleDto);
  }

  @Delete(norm.delete.path)
  @ApiOperation({ summary: norm.delete.tag })
  remove(@Param(norm.delete.arg) id: string) {
    return this.departmentService.remove(id);
  }
}
